package com.bb.blog.code.threading.example.atomic;

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

public class AtomicFieldUpdaterExample {
    public static void main(String[] args) {
        AtomicReferenceFieldUpdater<Student, Integer> atomicReferenceFieldUpdater = AtomicReferenceFieldUpdater.newUpdater(Student.class,Integer.class,"age");
        Student student = new Student();
        atomicReferenceFieldUpdater.getAndUpdate(student,(t)->{
            return t/2;
        });
        System.out.println(student.age);

    }


}

class Student{

    Student() {
        this.age = 10;
    }
    volatile Integer age;
}